<template>
    <HomePanel ref="target" title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
        <template #right>
            <XtxMore />
        </template>
       <template #default>
      <!-- <ul ref="pannel" class="goods-list">
        <li v-for="item in prdList" :key="item.id">
          <RouterLink to="/">
            <img :src="item.picture" alt="" />
            <p class="name">{{ item.name }}</p>
            <p class="price">&yen;{{ item.price }}</p>
          </RouterLink>
        </li>
      </ul> -->
      <!-- 商品组件 -->
      <HomeList :list="prdList"/>
    </template>
    </HomePanel>
</template>

<script>
import { ref } from 'vue'
import { findNew } from '@/api/home'
import HomePanel from './home-panel.vue'
import HomeList from './home-list.vue'
import { useObserver } from '@/hooks'
// 逻辑复用
const useNew = () => {
  // 商品列表
  const prdList = ref([])
  // 获取商品列表数据
  const getPrdList = async () => {
    const { result } = await findNew()
    // console.log(result)
    prdList.value = result
  }
  //   onMounted(() => {
  //     getPrdList()
  //   })
  return { prdList, getPrdList }
}
export default {
  name: 'HomeNew',
  components: {
    HomePanel,
    HomeList
  },
  setup () {
    const { prdList, getPrdList } = useNew()
    // 调用监控元素进入可视区域函数
    const { target } = useObserver(getPrdList)
    // // 商品列表
    // const prdList = ref([])
    // // 获取商品列表数据
    // const getPrdList = async () => {
    //   const { result } = await findNew()
    //   console.log(result)
    //   prdList.value = result
    // }
    // onMounted(() => {
    //   getPrdList()
    // })
    return { prdList, target }
  }
}
</script>

<style scoped lang='less'>

</style>
